<?php

require("../config.php");
include_once("functii.php");
include_once("restrictii.php");

$santier = addentities($_GET["obiect"]);
$query = mysql_query("SELECT * FROM c_cladiri");

$v1 = 0 ;
$v2 = 0 ;
$but_id = 0;

echo '<center><table border="0" cellspacing="0" cellpadding="0" width="400">
	    <tr>
		  <td background="img/tab2.gif" height="20" align="right">
		  <a href="javascript:void(0)" onMouseUp="javascript:ascunde_element(\'blocare_frame\');ascunde_element(\'constructie_frame\');" onMouseOver="javascript:animatie_but2(\'but_inchidere_construire\', 1,\'but_inchidere\')" onMouseOut="javascript:animatie_but2(\'but_inchidere_construire\', 0,\'but_inchidere\')" onMouseDown="javascript:animatie_but2(\'but_inchidere_construire\', 2,\'but_inchidere\')"><img src="img/but_inchidere.gif" border="0" id="but_inchidere_construire"></a>
		  </td>
		</tr>
		<tr>
		  <td background="img/dot.png" style="border-left: 2px #454f56 solid; border-right: 2px #454f56 solid">';

//// Cere toate cladirile din tabelul cu constante....
while($rez = mysql_fetch_array($query))
	{
	 // Verifica daca cladirea este construita
	 $rez_verificare_cladire = mysql_fetch_array(mysql_query("SELECT * FROM `cladiri` WHERE nume = '".$rez["id"]."' AND planeta = '".$planeta."'"));
	 $rez_in_constructie = mysql_num_rows(mysql_query("SELECT * FROM `actiuni_locale` WHERE `tip` = 'construire' AND `obiect` = '".$rez["id"]."' AND `planeta` = '".$planeta."'"));
	 // Daca cladirea nu este construita sau daca nu este in curs de construire
	 if(($rez_verificare_cladire["nume"] != $rez["id"]) && ($rez_in_constructie == 0))
	 	{
		// Verifica cerintele
		 $cerinte = explode(",",$rez["cerinte"]);
		 $i=0; 
		 $k=0;
		 while(isset($cerinte[$i]))
		 		{
				// Separa cerintele...
				 list($cladire, $nivel) = explode("@", $cerinte[$i]);
				// Vezi daca cladirea indeplineste cerintele necesare 
				 $verificare = mysql_num_rows(mysql_query("SELECT * FROM `cladiri` WHERE nume = '".$cladire."' AND nivel >= '".$nivel."' AND planeta = '".$planeta."'"));
				 if($verificare!=0)
				 		{
						 $k++;
						}
				 $i++;
				}	 
		// Compara daca au fost indeplinite toate cerintele
		 if($k==$i)
		 	{
			$but_id++;
			 echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td height="5" colspan="2"></td></tr>
				     <tr>
					   <td width="70" height="60"><img src="img/bdg_'.$rez["avatar"].'" width="70" height="60" border="0"></td>
					   <td height="20"><strong>'.$rez["nume"].'</strong></td>
					 </tr>
					 <tr>
					   <td colspan="2" style="padding: 5px; text-align: justify; text-indent: 15px; font-size: 14px;">
					     '.$rez["descriere"].'
					   </td>
					 </tr>
					 <tr>
					   <td colspan="2" style="padding: 5px; font-size: 12px"><div style="padding-top:6px; padding-bottom: 4px;"><strong>Cerinte:</strong> </div>
					     <img src="img/res_minerale.gif" align="absmiddle">Minerale: '.$rez["cost_minerale"].'&nbsp;
						 <img src="img/res_gaz.gif" align="absmiddle">Gaz: '.$rez["cost_gaz"].'&nbsp;
						 <img src="img/ico_durata.gif" align="absmiddle">Durata: '.date("i:s",$rez["timp_constr"]).'&nbsp;
						 <img src="img/res_populatie.gif" align="absmiddle">Locuri: '.$rez["cost_populatie"].'
					   </td>
					 </tr>
					 <tr>
					   <td colspan="2" align="right">';
					   $status = verificare_cladire($rez["id"], '0', $planeta);
					if ($status == 1)
					 echo '<a href="javascript:void(0)" onClick="javascript:actiuni(\'0\', \'construire\', \''.$santier.'\', \''.$rez["nume"].'\'); javascript:ascunde_element(\'blocare_frame\');ascunde_element(\'constructie_frame\');" onMouseOver="javascript:animatie_but(\'but_construieste'.$but_id.'\', 1,\'buton_mare\')" onMouseOut="javascript:animatie_but(\'but_construieste'.$but_id.'\', 0,\'buton_mare\')" onMouseDown="javascript:animatie_but(\'but_construieste'.$but_id.'\', 2,\'buton_mare\')"><div id="but_construieste'.$but_id.'" class="butoane_2" style="margin-left:3px;float:right">Construieste</div></a>';
					 else
					echo '<font color="red">'.$status.'</font>';   
					echo '</td<tr><td height="5" colspan="2"></td></tr></table>';
			}else{ $v1++; }
		 $v2++;
		 
		}
		else
		{
		 $v1++;
		}
	}
	 // Vezi cate cladiri ar trebui sa fie
	 $nr_randuri = mysql_num_rows($query);
	 // Daca nu au fost afisate toate cladirile anunta!
	 if($v1==$nr_randuri) { echo '<p style="padding: 10px; text-align: justify; text-indent: 10px; font-size: 12px; font-weight: bolder;">Momentan nu puteti construi alte tipuri de cladiri. Consultati sectiunea <a href="javascript:setare_cookie(\'ultimulFrame\',\'instructiuni\');schimba_continut(\'instructiuni\');ascunde_element(\'blocare_frame\');ascunde_element(\'constructie_frame\');">instructiuni</a> pentru detalii.</p>'; }

echo '	  </td>
		</tr>
		<tr>
		  <td background="img/tab4.gif" height="20" align="right">
		  &nbsp;
		  </td>
		</tr>
	  </table></center>';

mysql_close($db);

?>